export function throttle(fn, wait) {
    let delay = wait || 500
    let timer = null
    return function() {
        if (timer) {
            console.log('拦截');
            return
        }
        timer = setTimeout(() => {
            console.log('发送');
            fn.apply(this, arguments)
            timer = null
        }, delay)
    }
}


export function debounce(fn, wait) {
    let delay = wait || 500
    let timer
    return function() {
        let args = arguments;
        if (timer) {
            clearTimeout(timer)
            console.log('拦截')
        }
        let callNow = !timer
        timer = setTimeout(() => {
            console.log('发送')
            timer = null
        }, delay)
        if (callNow) fn.apply(this, args)
    }
}



export function getTimertype(endTime) { //返回当前的状态值

    let nowTime = new Date();

    let nowStamp = nowTime.getTime();
		// console.log(endTime,"endTime")
    let endStamp = getTimestamp(endTime.replace(
        new RegExp("-", "gm"),
        "/"
      ));
			
			// console.log(nowStamp,"nowStamp11111",endStamp)
    if (nowStamp > endStamp) {  //活动结束
        return 2
    }else{
			 return 1
		}
}

export function getTimestamp(time) { //返回时间戳
    return Date.parse(new Date(time))
}

module.exports = {
  throttle,
  debounce,
	getTimertype
}